package logic

import (
	"context"
	"errors"
	"house_srv/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderLogic {
	return &UpdateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateOrderLogic) UpdateOrder(in *house.UpdateOrderRequest) (*house.UpdateOrderResponse, error) {
	// todo: add your logic here and delete this line
	order := mysql.Order{}
	err := order.Update(in.OrderSn, int(in.OrderStatus))
	if err != nil {
		logx.Info("更新订单状态失败", err)
		return nil, errors.New("更新订单状态失败")
	}
	return &house.UpdateOrderResponse{}, nil
}
